<!DOCTYPE html>
<html lang="en">
<head>
	<#include "${managerViewPath}/include/macro.ftl"/>
  	<#include "${managerViewPath}/include/meta.ftl"/> 
</head>
<body>
<@ms.content>
		<@ms.contentBody>
		<@ms.nav title="零配件管理"/>
			<@ms.contentPanel>
			<@ms.searchForm  name="searchForm" id="searchForm" action="${managerPath}/pj/pjppList.do">
							<@ms.text label="配件品牌："  name="pjppName"  title="配件品牌"  placeholder="配件品牌" value="${pjppName?default('')}"   />
							<@ms.text label="配件类别："  name="pjlbName"  title="配件类别"  placeholder="配件类别" value="${pjlbName?default('')}"   />			  
						<@ms.searchFormButton>
								<@ms.queryButton id="submitSearch"/>
						</@ms.searchFormButton>
				</@ms.searchForm>
			
				<@ms.panelNav>
					<@ms.panelNavBtnGroup>
						<@ms.panelNavBtnAdd  id="totalAdd" title=""/>
						<@ms.panelNavBtnDel  id="totalDelete"/>
					</@ms.panelNavBtnGroup>
				</@ms.panelNav>
	              <@ms.table head=['序号',"<th style='text-align:center'>配件品牌</th>","<th style='text-align:center'>配件类别</th>"] checkbox="checkbox">
	           			<#if pjpplist?has_content>
	           				<#list pjpplist as list>
	                    	<tr>
	                    	<td style="text-align:center;width:10%;">
	                    		<input type="checkbox" name="checkbox${list_index+1}" value="${list.id?default(0)}">
	                    	</td>
	                    	<td style="width:5%">
	                    	${list_index+1}
	                    	</td>
	                    	 <td class="text-center">${list.pjppName?default("暂无")}</td>
	                    	 <td class="text-center">${list.pjlbName?default("暂无")}</td>
					         </tr>
	                    	</#list>
	                 		<#else>
	                 			<tr>
						            <td colspan="4" class="text-left">
						            	<@ms.nodata/>
									</td>
					          	</tr>
	        			</#if>
	        			</@ms.table>
	        			<#if page?has_content>
	        			<@ms.pagehelper page=page url="${managerPath}/pj/pjppList.do?${params}"/>
	        			</#if>	
			</@ms.contentPanel>		
		</@ms.contentBody>
		<!--=================模态框部分开始=================-->
		
		<!--修改/保存的模态框开始-->
		<@ms.modal modalName="update" title="">
			 <@ms.modalBody height="300">
				<@ms.form isvalidation=true name="updateTechnician" id="updateTechnician"  action=""  enctype="multipart/form-data">	
		    		<@ms.text name="pjppName"    label="配件品牌" title="配件品牌" maxlength="100" placeholder="请输入配件品牌" validation={"required":"true", "data-bv-notempty-message":"配件品牌不能为空"}/>
		    		<@ms.select  name="pjlbId" label="配件类别"  list=pJlist  id="pjlbId" listKey="id"  listValue="pjlbName" value="${pjlbId?default('')}" validation={"required":"true", "data-bv-notempty-message":"配件类别不能为空"}/>
		    	</@ms.form>		          	
		     </@ms.modalBody>
		     <@ms.modalButton>
	 			<@ms.savebutton id="updateButton"/>  
	 		 </@ms.modalButton>
	 		
		</@ms.modal>
		<!--修改/保存的模态框结束-->
		
		<!--多选删除的模态框开始-->
		<@ms.modal modalName="deleteAll" title="批量删除配件">
			 <@ms.modalBody>
				您确定删除您所勾选的配件吗？
		     </@ms.modalBody>
		     <@ms.modalButton>
	    		<@ms.button value="返回" id="closeDelete"/>  
	 			<@ms.button class="btn btn-danger" id="deleteButton" value="删除"/>  
	 		 </@ms.modalButton>
		</@ms.modal>
		<!--多选删除的模态框结束-->
		<!--单个删除的模态框开始-->
		<@ms.modal modalName="deleteRadio" title="删除配件">
			 <@ms.modalBody>
				您确定删除您所勾选的配件吗？
		     </@ms.modalBody>
		     <@ms.modalButton>
	    		<@ms.button value="返回" id="closeRadio"/>  
	 			<@ms.button class="btn btn-danger" id="deleteRadio" value="删除"/>  
	 		 </@ms.modalButton>
		</@ms.modal>
		<!--单个删除的模态框结束-->
		<!--=================模态框部分结束=================-->
		</@ms.content>
</body>
<script>
		$("#submitSearch").click(function() {
				$("#searchForm")[0].submit();
			});
			
			var URL='';
	//模态框的操作
	$(function () {	
		$("#totalAdd").click(function(){
			$("#updateTitle").text("配件品牌");	
			$("#updateButton").text("保存");
			URL="${managerPath}/pj/ppsave.do";
	 		$(".update").modal();
	 	});
	 	$("#closeUpdate").click(function(){
	 		$(".update").modal("hide");
	 	});
	 	
	 	$("#closeDelete").click(function(){
	 		$(".deleteAll").modal("hide");
	 	});
	 	
	 	$("#closeRadio").click(function(){
	 		$(".deleteRadio").modal("hide");
	 	});
	 	
	 	$("#closeSaveUrl").click(function(){
	 		$(".managerPageModel").modal("hide");
	 	});	
	});
	 	
 		//全选
	   	$("input[name='allCheckcheckbox']").on("click",function(){   
			if(this.checked){
			      $("input[name^='checkbox']").each(function(){this.checked=true;});
			}else{
			      $("input[name^='checkbox']").each(function(){this.checked=false;});   
			}   
		}); 
		
	 //点击更新按钮
	 $("#updateButton").click(function() {
			var formData = $("#updateTechnician").serialize();
			var vobj = $("#updateTechnician").data('bootstrapValidator').validate();
			var buttonHtml = $("#updateButton").html();
			if(vobj.isValid()){
					$.ajax({
					   type: "post",
					   dataType: "json",
					   url:  URL,
					   data: formData, 
					   beforeSend:function(){
					   		$("#updateButton").text($("#updateButton").text()+"中");
					   		$("#updateButton").attr("disabled",true);
					   },
					   success: function(msg){ 
					   		if(msg.flag==0){
					   			alert(buttonHtml+"成功");
					   			location.reload();
					   		}else{
					   			alert(msg.resMsg);
					   			$("#updateButton").text(buttonHtml);
					   			$("#updateButton").attr("disabled",false);
					   		}
					   },error: function(){
					   }
				});
			 }
			
	 });

	 $("#totalDelete").click(function(){
	 	var radioData = $("input[name^='checkbox']").serialize();
		if(radioData!=""){
			$(".deleteAll").modal();//打开
		}else{
			alert("请选择需要删除的配件品牌！");
		}
	 });
	 
	 
	 	//批量删除配件品牌
		$("#deleteButton").click(function(){
			var count = 0;
			var checkboxData = $("input[name^='checkbox']").serialize();
			$("input[name='checkbox']").each(function(){
				if(this.checked==true){
					
				}
			});
			
			if(checkboxData.length != 0) {
				$.ajax({
				   type: "post",
				   dataType: "json",
				   url:  "${managerPath}/pj/allDeletePP.do",
				   data: checkboxData,
				   beforeSend:function(){
				   		$("#deleteButton").text("删除中");
				   		$("#deleteButton").attr("disabled",true);
				   },
				   success: function(msg){
				   if(msg.flag==1){
				   alert(msg.resMsg);
				   $("#deleteButton").attr("disabled",false);
				   $("#deleteButton").text("删除")
				   }else{
				   alert("删除配件品牌成功");
				   		location.reload();
				   }
				   		
				   },error: function(){
				   	  alert("批量删除配件品牌失败");
				      $(".deleteAll").modal("hide");
				   }
				});
			 } else {
				alert("删除失败，请先选择配件品牌");
				$(".deleteAll").modal("hide");
			 }
		 });
		 
		 $("[id^='resetButton']").bind({
		 click:function(){
		 $("[name='pjppName']").val(function(){return ""});
		  $("[name='pjlbName']").val(function(){return ""});
		 $("#submitSearch").click();
		 }
		 })	
</script>
</html>